require "util"
require "logUtil"
require "setting"

-- 负载ui 
function fz_ui()
    x, y = findMultiColorInRegionFuzzy(0xefcc65, "42|-1|0xfefd78,89|-2|0xfef9a3,111|-2|0xf2d164,-438|66|0xf8da80,-155|134|0xfbe666,66|116|0xa35642,82|57|0x455a70,-150|45|0xe4bea8,-147|6|0x3f0c0e,-360|8|0x40090e,-356|-5|0x911c17,-191|-8|0xfb3d2f", 85, 484, 4, 1071, 252, 0, 0)

    if x > -1 then
        logger("府宅界面", LOG_DEBUG)
        return true
    end
end

-- 府宅关闭
function fz_ui_gb()
    x, y = findMultiColorInRegionFuzzy(0xefcc65, "42|-1|0xfefd78,89|-2|0xfef9a3,111|-2|0xf2d164,-438|66|0xf8da80,-155|134|0xfbe666,66|116|0xa35642,82|57|0x455a70,-150|45|0xe4bea8,-147|6|0x3f0c0e,-360|8|0x40090e,-356|-5|0x911c17,-191|-8|0xfb3d2f", 85, 484, 4, 1071, 252, 0, 0)
    if x > -1 then
        click(x, y)
        logger("府宅界面关闭", LOG_DEBUG)
        return true
    end
end

function fz_shouZhi()
    x, y = findMultiColorInRegionFuzzy(0xfefefe, "27|31|0xf1cfc1,13|15|0xf3cebf,15|59|0xf4d2ce,48|83|0xf9ddce,44|31|0xf1cac9,62|26|0xf8dad1,83|26|0xf4d7d3,71|67|0xf7d8ce,13|41|0xfdc248,5|51|0xfefcf9,59|115|0x030223", 85, 16, 922, 1059, 1517, 0, 0)
    if x > -1 then
        click(x, y)
        logger("点击：手指", LOG_DEBUG)
        return true
    end
end

function fz_HuangKuang()

    x, y = findMultiColorInRegionFuzzy(0xebd4c4, "-117|-34|0xdeb339,-116|-107|0xd1a727,-70|-126|0xd7ae23,-13|-126|0xbda535,-13|-77|0xeedfd1", 80, 16, 922, 1059, 1517, 0, 0)

    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xebd4c4, "-117|-34|0xdeb339,-116|-107|0xd1a727,-70|-126|0xd7ae23,-13|-126|0xbda535,-13|-77|0xeedfd1", 80, 16, 922, 1059, 1517, 0, 0)
    end
    if x > -1 then
        click(x, y)
        logger("点击：黄框", LOG_DEBUG)
        return true
    end
end


-- 华安
function fz_huaAn2()
    x, y = findMultiColorInRegionFuzzy(0x5f4133, "-12|-112|0x7f4a32,-128|-110|0x2b120f,-153|78|0x060505,-13|149|0x030202,88|-84|0x18110d,-65|-205|0xd8bda4,-60|-281|0xf0e5cc,-141|-287|0xf0e5cc,-13|-289|0xf0e5cc", 85, 14, 748, 1079, 1634, 0, 0)
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0x936945, "0|294|0x704d38,40|211|0x060505,-1|160|0xf2bf94,89|215|0x201b16,57|68|0x604234,52|-45|0x7f4a32,-69|-46|0x2b120f,-100|140|0x080707,-101|200|0x0e0c0c,14|-109|0xd9b596,3|-150|0xdec5af,182|361|0x9f978d,108|277|0x908982,-140|333|0x9e968c", 90, 0, 878, 574, 1686, 0, 0)
    end
    if x > -1 then
        click(x, y )
        logger("点击：华安", LOG_DEBUG)
        return true
    end
end


-- 师爷
function fz_shiYe()
    x, y = findMultiColorInRegionFuzzy(0x1a2135, "16|46|0x13142b,-8|62|0x13142b,14|-86|0xc8855c,-7|-118|0x0a090a,-1|-169|0xf0e5cc,-63|-180|0xf0e5cc,-97|13|0x1b130f,-60|87|0xb0a89a", 85, 3, 738, 1068, 1293, 0, 0)
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0x181f35, "-95|10|0x1a120f,5|-124|0x0e0d0e,-7|-57|0x334658,44|-144|0x1d1712,-2|178|0x232f49,42|2|0x33445b,0|138|0x28354c,3|124|0x25324c,-58|88|0xb2a99b", 90, 9, 882, 1059, 1314, 0, 0)
    end
    if x > -1 then
        click(x, y )
        logger("点击：师爷", LOG_DEBUG)
        return true
    end
end

-- 子嗣
function fz_zhiSi()
    x, y = findMultiColorInRegionFuzzy(0xc85453, "36|25|0xc04850,33|-72|0xe9c0a4,18|-105|0xeedbc7,10|-189|0xf0e5cc,-33|-192|0xf0e5cc,-85|111|0x18110d,-32|78|0x17161f,-34|36|0x17161f,5|138|0xcb595a,-6|162|0x424242", 85, 14, 748, 1079, 1634, 0, 0)
    if x > -1 then
        click(x, y )
        logger("点击：子嗣", LOG_DEBUG)
        return true
    end
end
-- 红颜
function fz_hongYan()

    x, y = findMultiColorInRegionFuzzy(0x070202, "-102|0|0x26191b,-85|9|0xb34945,-75|95|0xbb8f6b,-46|2|0xe1c9b4,-67|-131|0xe8d1c0,-66|-209|0xf0e1d3,-57|-291|0xf0e5cc,-109|-300|0xf0e5cc,-12|-299|0xf0e5cc,62|-134|0x1a130e", 85, 13, 759, 1061, 1654, 0, 0)
    if x > -1 then
        click(x, y )
        logger("点击：红颜", LOG_DEBUG)
        return true
    end
end



-- 查找需要操作的事件
function fz_find()
    x, y = findMultiColorInRegionFuzzy(0x48342d, "19|-14|0x48342d,-25|-15|0x48342d,-4|-16|0xf0e5cc,-32|-26|0xf0e5cc,25|-26|0xf0e5cc,8|-72|0xf4ecda,-27|-72|0xf4ecda,-24|-82|0x48342d,5|-84|0x48342d", 78, 9, 514, 879, 1650, 0, 0)
    if x > -1 then

        click(x, y + 200)
        return true
    end
end

-- 检测接下来的操作
function fz_next()
    x, y = findMultiColorInRegionFuzzy(0xe6b520, "19|-5|0xe6b825,50|-4|0xe5c02f,83|-4|0xe6cb45,104|-4|0xe5cf4b,-2|31|0xe7b621,-4|35|0xd5a411,-4|66|0xd7a613,-5|90|0xd49d13,-4|125|0xd7a612", 80, 0, 0, 1079, 1919, 0, 0)
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xf6d6cf, "24|-14|0xf6d6cf,16|-40|0xf7d7d0,-17|-16|0xf8dad2,-50|-31|0xf2cccb,-41|-55|0xf6e3dd,-21|-58|0xf7e1da,-2|-62|0xf7d8d0,14|-67|0xf5d8d4,-55|-77|0xf2d1c4,-7|22|0x030223,22|42|0x558b7b,52|17|0x76cac2,66|7|0x96d4d1,49|22|0x69b8b3", 80, 0, 0, 1079, 1919, 0, 0)
    end

    if x > -1 then
        click(x, y)
        return true
    end

end



-- 检测主线任务
function fz_jc_zhuXian()
    x, y = findMultiColorInRegionFuzzy(0xfefec3, "-1|18|0xfefe3e", 78, 7, 1504, 403, 1655, 0, 0)
    if x > -1 then

        click(x, y)
        logger("检测主线任务", LOG_DEBUG)
        return true
    end
end

-- 检查限时奖励
function fz_jc_xianshijianli()

    x, y = findMultiColorInRegionFuzzy(0xe01c10, "-1|-9|0xf95f37,6|-7|0xf55430,-7|0|0xe72b17,-57|10|0xe43f17,-71|16|0xbe280d,-83|27|0xaf240b", 80, 374, 256, 547, 446, 0, 0)
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xe52918, "-72|20|0xbf290d,-82|29|0xae230a,-53|36|0xfee238,-2|25|0x3f5d7f", 90, 543, 270, 729, 438, 0, 0)
    end
    if x > -1 then

        click(x, y)
        logger("检查限时奖励", LOG_DEBUG)
        return true
    end
    return false
end

-- 检查任务
function fz_jc_renWu()
    x, y = findMultiColorInRegionFuzzy(0xe22113, "-1|-7|0xf55330,-34|3|0xc94e43,-16|20|0xbd443b,-1|37|0xbb423b,-76|70|0xfbf4d8", 80, 375, 1743, 548, 1911, 0, 0)

    if x > -1 then

        click(x, y)
        logger("检查任务", LOG_DEBUG)
        return true
    end
    return false
end

-- 检查成就

function fz_jc_chengJiu()
    x, y = findMultiColorInRegionFuzzy(0xe72e1b, "8|-4|0xf4502e,-44|21|0x8e6539,-68|27|0xb3793d,-60|81|0xe4c17d", 80, 555, 1749, 712, 1912, 0, 0)
    if x > -1 then
        click(x, y)
        logger("检查成就", LOG_DEBUG)
        return true
    end
end

-- 资产
function fz_ZiChan_UI()
    x, y = findMultiColorInRegionFuzzy(0xfee9a0, "-112|0|0x6a2320,-47|5|0x3b0b00,14|24|0x370a00,25|5|0x3b0b00,73|3|0x3a0b00,140|3|0x2c0800,289|-3|0x72281c,147|-7|0xd8c898,155|7|0x3b0b00,4|-1|0xfeeba4,5|8|0xfedf82,-3|-21|0x46271b,45|5|0xd4b76f,56|12|0xfeda76,109|10|0xfedd7c,147|-4|0xfeefaf,113|-15|0xebe7c1", 78, 0, 0, 1079, 1919, 0, 0)
    if x > -1 then
        click(x, y)
        logger("资产界面", LOG_DEBUG)
        return true;

    end
end



-- 资产
function fz_huaAn()
    x, y = findMultiColorInRegionFuzzy(0xcf9870, "37|-179|0xc08f5e,47|-137|0xaa7b50,-58|13|0x0d0102,50|-136|0xae7e52,-12|169|0x6f4c37,-20|105|0x6a4934,45|53|0x030202,-103|-49|0x050404", 78, 0, 0, 1079, 1919, 0, 0)
    if x > -1 then
        click(x, y)
        logger("点击华安", LOG_DEBUG)
        return true;

    end
end




-- 资产-关闭
function fz_ZiChan_UI_GB()
    local x, y = findMultiColorInRegionFuzzy(0xfedf44, "16|-6|0xeabf45,7|13|0xfec61c,-18|18|0xfebf12,-9|-6|0xfee750", 70, 912, 67, 1078, 232, 0, 0)
    if x > -1 then
        click(x, y)
        logger("资产界面关闭", LOG_DEBUG)
        return true;
    end
end

--资产- 经营
function fz_ZiChan_jingYing()
    x, y = findMultiColorInRegionFuzzy(0xc46c2e, "84|1|0xc96f2f,170|1|0xc26a2d,196|40|0x82431c,-11|60|0x7f4615,209|57|0x864b1b,228|131|0x252034,-345|136|0x252034,-697|-20|0x211c2e", 80, 0, 0, 1079, 1919, 0, 0)
    if x > -1 then
        click(x, y)
        logger("资产- 经营", LOG_DEBUG)
        return true;
    end
end


-- 政务
function fz_zhenWu_UI()
    x, y = findMultiColorInRegionFuzzy(0xfee79a, "-111|-10|0x3b0b00,-60|0|0xf9e296,-42|-19|0x3b0b00,-3|-13|0xfcf7c6,56|7|0xfede80,46|-19|0x2e0900,64|-1|0x2f0900,80|-9|0x2d0800,118|-13|0x340b00,-74|3|0x2c0800,-51|-3|0x361409,-66|-8|0x2c0800,28|-1|0x2f0800,53|-10|0x2d0901,101|10|0x2c0800,84|5|0x2c0800,121|-3|0xead796,55|7|0xfede80,8|9|0xfedc79", 78, 0, 0, 1079, 1919, 0, 0)
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xfedd7d, "-23|-14|0xfef0b1,-53|-13|0x3b0b00,9|-25|0x3b0b00,79|-17|0xfef4bc,114|-18|0xfef5bf,133|-8|0xfee79a,170|-10|0xfeeaa1,154|-8|0xfee79a,111|0|0xfedd7d,193|-11|0x3b0b00", 85, 350, 22, 762, 241, 0, 0)
    end
    if x > -1 then
        logger("政务界面", LOG_DEBUG)
        return true;
    end
end


-- 政务-关闭
function fz_zhenWu_UI_GB()
    local x, y = findMultiColorInRegionFuzzy(0xfeda3c, "13|-9|0xfeea55,13|10|0xfec820,-19|15|0xfec115,-5|-8|0xfee750,-30|0|0xa41a0c,30|0|0xa11a0c", 78, 897, 34, 1077, 223, 0, 0)
    if x > -1 then
        click(x, y)
        logger("政务界面关闭", LOG_DEBUG)
        return true;
    end
end
-- 政务-检测是否存在政务
function fz_zhenWu_zw()
    local x, y = findMultiColorInRegionFuzzy(0xd2c3a7, "-19|-23|0xc2682b,27|-23|0xc56c2f,38|1|0xb75f25,25|27|0x643419,-24|28|0x643316,-31|10|0xfff7d6,-24|4|0xfff7d6,0|0|0xd2c3a7", 78, 759, 1524, 1074, 1819, 0, 0)
    if x > -1 then
        logger("没有政务需要处理", LOG_DEBUG)
        return false;
    end
    return true
end

-- 政务-使用政务领
function fz_zhenWu_zhengWuLing()
    local x, y = findMultiColorInRegionFuzzy(0xd2c3a7, "-19|-23|0xc2682b,27|-23|0xc56c2f,38|1|0xb75f25,25|27|0x643419,-24|28|0x643316,-31|10|0xfff7d6,-24|4|0xfff7d6,0|0|0xd2c3a7", 78, 759, 1524, 1074, 1819, 0, 0)
    if x > -1 then
        click(x, y)
        logger("没有政务需要处理", LOG_DEBUG)
        return false;
    end

end

-- 政务--获取资源
function fz_zhenWu_ziYuan()
    --601,1567
    click(601, 1567)
end

-- 政务--获取政绩
function fz_zhenWu_zhenJi()
    --568,1744
    click(568, 1744)
end

-- 儿子界面
function fz_erZi_ui()
    x, y = findMultiColorInRegionFuzzy(0xfef0b0, "292|4|0x72281c,187|-1|0x3b0b00,-92|-2|0x3b0b00,-18|-20|0x310900,5|23|0x3b0b00,61|-2|0xfef2b8,134|18|0xfed973,20|-11|0xefecc4,-37|14|0xfedd7e,-48|20|0x390c00,-39|12|0xfee084,-69|-5|0xb1a27e,-13|9|0xab8f57,-5|18|0x2d0900,51|7|0x2c0800,72|7|0x2d0800,80|-10|0x2c0800", 78, 0, 0, 1079, 1919, 0, 0)

    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xfed738, "0|40|0x92100a,-32|-2|0x9b150c,-92|47|0x0c0a0a,-453|-5|0xfef0b1,-521|-14|0xfefacd,-562|-9|0xfef5be,-574|0|0xfee89e,-550|13|0xfed973,-504|-15|0xfefbd0,-14|12|0xfec115,9|9|0xfec61c,0|40|0x92100a,-34|-4|0x97120b,31|1|0x9f180c", 86, 325, 38, 1079, 218, 0, 0)

    end
    if x > -1 then
        logger("儿子界面", LOG_DEBUG)
        return true
    end
end
-- 儿子界面-关闭
function fz_erZi_ui_GB()
    local x, y = findMultiColorInRegionFuzzy(0xfeda3c, "-32|-1|0x9d150c,1|-29|0x9c150c,28|1|0xa71c0d,-4|34|0x9e170b,-14|-13|0xfeef5d,-10|12|0xfec61c,-36|-24|0x93100a,14|-14|0xfef15f,14|11|0xfec61c", 78, 896, 43, 1077, 229, 0, 0)
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xfed738, "0|40|0x92100a,-32|-2|0x9b150c,-92|47|0x0c0a0a,-453|-5|0xfef0b1,-521|-14|0xfefacd,-562|-9|0xfef5be,-574|0|0xfee89e,-550|13|0xfed973,-504|-15|0xfefbd0,-14|12|0xfec115,9|9|0xfec61c,0|40|0x92100a,-34|-4|0x97120b,31|1|0x9f180c", 86, 325, 38, 1079, 218, 0, 0)

    end
    if x > -1 then
        click(x, y)
        logger("儿子界面关闭", LOG_DEBUG)
        return true
    end
end
-- 儿子界面-培养
function fz_erZi_peiYang()

    x, y = findMultiColorInRegionFuzzy(0xc0682d, "168|0|0xc26a2e,0|26|0x864218,137|28|0x984e1f,-18|50|0x7e4515,172|53|0x7a4316,-578|84|0x2ed5e9,-578|99|0x0e4e96,-578|91|0x1b96c2", 85, 148, 959, 987, 1113, 0, 0)
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xfff7d6, "-21|-27|0xc66f30,49|-29|0xc77130,-75|-25|0xc1692d,110|-22|0xbd652a,91|13|0x6e391a,16|33|0x552d15,-61|33|0x753d17,108|36|0x7e4516,4|8|0x694835,3|-6|0xc36626,31|10|0xa48c74,41|1|0xfff7d6,-12|-6|0xf1e6c7,9|6|0xfff7d6", 78, 0, 0, 1079, 1919, 0, 0)
    end

    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xc1692d, "132|3|0xc2672a,6|17|0xb25b23,139|18|0xa95621,-26|48|0x7f4615,166|49|0x804716,87|33|0x87451c,51|22|0xfff7d6,68|28|0x9e4e1c,62|8|0xd06c29,111|38|0x6c3819,112|29|0x964b1c,115|21|0xb05820,125|21|0xae5821,119|31|0x89471d,21|28|0x91491c,15|21|0xb05a22,15|22|0xac5822,15|22|0xac5822", 85, 693, 944, 984, 1066, 0, 0)
    end
    if x > -1 then
        click(x, y)
        logger("子嗣培养", LOG_DEBUG)
        return true;

    end
end


function fz_erZi_keJu()
    x, y = findMultiColorInRegionFuzzy(0xb81a05, "129|2|0xa41005,118|46|0x440100,14|44|0x500100,-36|48|0x5f0000,159|47|0x640000,6|26|0x6c0000,17|26|0x670100,120|26|0x620000,104|12|0x870602,46|32|0x5a0100,70|33|0x4a0301,34|16|0xfff7d6,34|20|0xfff7d6,55|26|0xfff7d6,75|14|0xfff7d6,86|14|0xfff7d6,80|23|0xfff7d6,80|30|0xfff7d6", 95, 692, 944, 993, 1066, 0, 0)
    if x > -1 then
        click(x, y)
        logger("子嗣科举", LOG_DEBUG)
        return true;
    end
end




-- 儿子界面-解锁
function fz_erZi_jieSuo()
    x, y = findMultiColorInRegionFuzzy(0xeedbc7,"-14|110|0xc65154,68|140|0xc85858,58|190|0x353345,-51|181|0x17161f,-69|146|0x612727,9|236|0xcc5759,-23|157|0x1b1c2a,-23|269|0x434343,-75|205|0x938c84,-58|331|0x242526,153|58|0x110b0b,166|57|0x542323,-321|-19|0x10151e,-305|19|0x030713,183|171|0x5c422e,167|168|0x4f211c,147|182|0x412e38,-236|134|0x4b4743,-226|97|0x4d4945", 95, 180, 1100, 997, 1705, 0, 0)
    if x > -1 then
        click(x, y)
        logger("子嗣.解锁", LOG_DEBUG)
        return true;
    end
end

-- 儿子界面-赐名
function fz_erZi_ciMing()
    x, y = findMultiColorInRegionFuzzy(0xcf2e09, "130|5|0xc21f08,9|23|0x790502,122|20|0x8a0703,15|42|0x5e0000,169|55|0x5c0000,-25|55|0x630100,-587|95|0x1883b7,-586|86|0x2fd6e9,-577|93|0x1b96c2,-583|97|0x1570ac", 85, 155, 955, 965, 1098, 0, 0)
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xaf1307, "58|-10|0xc92409,99|43|0x700000,-99|44|0x670100,-64|14|0x730301,63|18|0x6e0201,16|26|0x690100,15|11|0x800703,-1|17|0x700301,0|29|0x5e0100,-31|16|0xfff7d6,-9|10|0xfff7d6,12|20|0xfff7d6,-8|20|0xfff7d6,9|32|0xfff7d6,28|32|0xfff7d6,-30|34|0x5c0100,-26|18|0xfff7d6,-35|18|0xfff7d6", 80, 663, 901, 1049, 1084, 0, 0)
    end

    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xa51005, "129|1|0x9d0f05,-38|45|0x5f0000,159|43|0x5e0000,81|25|0x6d0201,79|10|0x830703,8|15|0x790301,108|16|0x740301,75|19|0xfff7d6,54|9|0xfff7d6,44|19|0xfff7d6,77|17|0xfff7d6,79|10|0x830703,90|15|0x730301", 85, 688, 943, 987, 1068, 0, 0)
    end
    if x > -1 then
        click(x, y)
        logger("子嗣赐名", LOG_DEBUG)
        return true;

    end
end




-- 儿子界面-赐名_确定
function fz_erZi_ciMing_queDing()
    x, y = findMultiColorInRegionFuzzy(0xf9efcf, "276|7|0xaa5721,0|18|0xfff7d6,9|14|0x914417,-13|6|0xb85c20,-12|-16|0xce6c29,26|11|0xa3531f,-22|25|0x663316,-62|7|0xb35f24,402|8|0xa1511e,296|3|0xb95b20", 78, 162, 1017, 899, 1164, 0, 0)
    if x > -1 then
        click(x, y)
        logger("子嗣赐名确定", LOG_DEBUG)
        return true;


    end
end


-- 儿子界面-恢复 不能恢复（补元丹）
function fz_erZi_huiFu_No()

    x, y = findMultiColorInRegionFuzzy(0x9d0c05, "138|-15|0xca2209,5|13|0x790301,131|12|0x740301,-30|41|0x600000,164|40|0x640000,-590|78|0x292d39,-589|87|0x282c38,-582|85|0x282c38,-597|80|0x242731", 85, 108, 960, 1013, 1115, 0, 0)
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0x710301, "-84|-25|0xb61807,77|-22|0xb41607,93|26|0x6e0000,-97|26|0x6a0000,-23|-9|0xfff7d6,-19|-9|0xfff7d6,-30|-7|0xfff7d6,-12|3|0xfff6d6,-21|10|0x5d0403,-12|15|0x560100,-3|9|0x5c0100,11|8|0xfff7d6,27|8|0xfff7d6,20|14|0xfff7d6,15|14|0xfff7d6,17|-11|0xf4ebcb,7|-4|0xfff7d6,7|-1|0xfff7d6,30|-2|0xfff7d6", 85, 666, 939, 965, 1080, 0, 0)
    end


    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xb01706, "127|1|0xa30e05,-30|44|0x630100,163|43|0x610000,48|7|0xfff7d6,76|24|0xfff7d6,84|30|0xfff7d6,36|15|0xfff7d6,36|7|0xfff7d6,36|28|0xfff7d6,95|15|0xfff7d6,73|15|0xfff7d6,75|4|0xfff7d6,55|21|0xfff7d6", 85, 691, 947, 976, 1065, 0, 0)
    end

    local needClick = false
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0x1c304d, "-3|-15|0x274165,-142|23|0x122f4a,26|23|0x122f4a,-542|-10|0x243d5f,-411|-9|0x223a5b,-550|20|0x0f1d33,-431|15|0x122038,-404|21|0x14334f,-280|-246|0x2d92e6,-257|-279|0x8cb2bb,-427|-393|0xfecf92,-102|-395|0xfecf92,-465|94|0xfecf92,-157|94|0xfecf92", 85, 40, 684, 1053, 1213, 0, 0)
        needClick = true;
    end


    if x > -1 then
        if needClick then
            click(x, y)
        end
        logger("子嗣精力用完了", LOG_DEBUG)
        return true;

    end
end



function fz_meiPo_jiesuo()
    x, y = findMultiColorInRegionFuzzy(0xebc3b2, "-95|68|0x130b08,-98|124|0x19120e,-51|13|0x88482f,24|252|0x965138,-20|339|0x7e4b3a,-85|320|0x5e5545,-86|183|0x221915,-13|68|0xe0ac98,69|276|0x5d5547,-21|96|0x5f7d60,-15|216|0x4f6e5c,-30|307|0x617d6c,-15|235|0x506e5c,73|-37|0xf5f0dd", 85, 605, 853, 1077, 1473, 0, 0)
    if x > -1 then
        if x > -1 then
            logger("媒婆解锁", LOG_DEBUG)
            return true;

        end
    end

end


-- 红颜界面-培养
function fz_hongYan_ui()
    x, y = findMultiColorInRegionFuzzy(0xdacfa0, "318|12|0x6f271d,-118|-12|0x370a00,-112|21|0x3b0b00,-46|-15|0x350900,59|-14|0x370a00,59|8|0x2c0800,37|21|0x2c0800,86|4|0xfeefaf,102|13|0x2c0800,-62|6|0x2e0800,-42|3|0x330900,-60|-5|0xf2edc2,-52|10|0xa68c5b,-79|6|0xfeeca8,1|1|0x918161,60|10|0x2c0800,36|21|0x2c0800,32|16|0xfedf82", 78, 0, 0, 1079, 1919, 0, 0)

    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xfed535, "-12|11|0xfec115,8|7|0xfec820,1|32|0x9a140b,-32|-9|0x99140b,-84|45|0x321500,-413|-4|0xfeeeac,-440|-8|0xfef3bb,-555|-12|0xfef9c8,-555|5|0xfee189,-463|-4|0xfeeeac,-555|7|0xfedf82,-350|-3|0x3b0b00", 86, 349, 24, 1079, 218, 0, 0)

    end
    if x > -1 then
        logger("红颜界面", LOG_DEBUG)
        return true;

    end
end



-- 红颜-随机传唤
function fz_hongYan_suiJiChuanHuan()
    local x, y = findMultiColorInRegionFuzzy(0xfff7d6, "-89|-27|0xc26a2e,-25|-25|0xca6e2d,97|0|0xa6501c,33|24|0x5e3119,-48|-4|0xfff7d6,-11|1|0xfff7d6,4|-4|0xb75d21,32|8|0x9d4f1d,66|-3|0xfff7d6,8|0|0xfff7d6,-25|0|0xfff6d6,-32|6|0xfff7d6,36|2|0xfff7d6,41|8|0x984f1e", 78, 0, 0, 1079, 1919, 0, 0)

    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0x834119, "193|-27|0xb96026,-14|23|0x7e4516,205|21|0x824816,-18|67|0x5a2518,144|69|0x5b2619,-20|-90|0x190804,140|-90|0x190804,76|9|0x763c18,9|41|0x4e3017,12|-53|0x4e3017", 90, 681, 1718, 1044, 1914, 0, 0)
    end
    if x > -1 then
        click(x, y)
        logger(" 红颜-随机传唤", LOG_DEBUG)
        return true
    end
end
-- hongYan
function fz_hongYan_huiFuJinLi()

    x, y = findMultiColorInRegionFuzzy(0xc01a08, "85|1|0xc42608,190|1|0xc01908,-4|60|0x620000,221|58|0x6b0000,53|20|0xfff7d6,116|27|0xfff7d6,133|21|0xfff7d6,133|17|0xfff7d6,162|22|0xfff7d6", 85, 650, 1668, 1067, 1911, 0, 0)
    if x > -1 then
        if x > -1 then
            logger("红颜没精力了", LOG_DEBUG)
            return true
        end
    end
end

-- 红颜-生孩子
function fz_hongYan_haizi()
    local x, y = findMultiColorInRegionFuzzy(0x8b4116, "-3|-24|0xfff7d6,55|-25|0xc96827,-63|-24|0xc76829,176|2|0x090302,-202|2|0x090302,-352|-20|0xbb5f23,-500|-20|0xc26426", 78, 155, 1414, 1017, 1635, 0, 0)
    if x > -1 then
        click(x, y)
        logger("红颜得子", LOG_DEBUG)
        return true
    end
end



-- 红颜关闭
function fz_HongYong_GB()
    local x, y = findMultiColorInRegionFuzzy(0xfed332, "-32|-4|0xa0180c,3|-34|0x9a140b,30|-6|0xa0180c,-16|11|0xfec115,-10|-14|0xfeeb56,17|-16|0xfeef5d,7|5|0xfeca24", 78, 0, 0, 1079, 1919, 0, 0)
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xdacfa0, "318|12|0x6f271d,-118|-12|0x370a00,-112|21|0x3b0b00,-46|-15|0x350900,59|-14|0x370a00,59|8|0x2c0800,37|21|0x2c0800,86|4|0xfeefaf,102|13|0x2c0800,-62|6|0x2e0800,-42|3|0x330900,-60|-5|0xf2edc2,-52|10|0xa68c5b,-79|6|0xfeeca8,1|1|0x918161,60|10|0x2c0800,36|21|0x2c0800,32|16|0xfedf82", 78, 0, 0, 1079, 1919, 0, 0)
    end

    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xfed535, "-12|11|0xfec115,8|7|0xfec820,1|32|0x9a140b,-32|-9|0x99140b,-84|45|0x321500,-413|-4|0xfeeeac,-440|-8|0xfef3bb,-555|-12|0xfef9c8,-555|5|0xfee189,-463|-4|0xfeeeac,-555|7|0xfedf82,-350|-3|0x3b0b00", 86, 349, 24, 1079, 218, 0, 0)
    end
    if x > -1 then
        click(x, y)
        logger("红颜界面关闭", LOG_DEBUG)
        return true
    end
end



-- 限时奖励
function fz_xsjl_ui()
    x, y = findMultiColorInRegionFuzzy(0x85491a, "-32|7|0x84481a,9|5|0x85481a,-17|32|0x000000,6|34|0x000000,20|79|0x4d2702,-129|42|0x6a4b25,-252|-1|0x5f3509,-322|21|0x221507,-495|24|0x221507,-524|3|0xca3311,-587|2|0xc73111,-440|1|0xc43010,-364|-1|0xbf2f10,-251|30|0x644621", 85, 346, 64, 1073, 138, 0, 0)

    if x > -1 then
        logger("限时奖励界面", LOG_DEBUG)
        return true
    end
    return false

end

-- 限时奖励
function fz_xsjl_ui_gb()

    x, y = findMultiColorInRegionFuzzy(0x85491a, "-32|7|0x84481a,9|5|0x85481a,-17|32|0x000000,6|34|0x000000,20|79|0x4d2702,-129|42|0x6a4b25,-252|-1|0x5f3509,-322|21|0x221507,-495|24|0x221507,-524|3|0xca3311,-587|2|0xc73111,-440|1|0xc43010,-364|-1|0xbf2f10,-251|30|0x644621", 85, 346, 64, 1073, 138, 0, 0)
    if x > -1 then
        click(x, y)
        logger("限时奖励界面关闭", LOG_DEBUG)
        return true
    end
    return false
end

-- 限时奖励 查找可以领取奖励的活动
function fz_xsjl_findHuoDong()

    local x, y = findMultiColorInRegionFuzzy(0xe41d0c, "5|-17|0xfd8657,15|-13|0xee7240,11|0|0xe92510,-5|-4|0xf03c1d,-4|-10|0xf3512d", 78, 688, 342, 1073, 1815, 0, 0)
    if x > -1 then
        click( x, y )
        logger("查找可以领取奖励的活动", LOG_DEBUG)
        return true
    end
    return false
end


-- 限时活动领取奖励
function fz_xsjl_lingQu()
    x, y = findMultiColorInRegionFuzzy(0xbf672c, "162|5|0xba6126,182|44|0x804716,-42|22|0x040b09,-76|23|0x040b09,37|-28|0x040b09,45|73|0x040b09", 85, 659, 352, 972, 1675, 0, 0)

    if x > -1 then
        click(x, y)
        logger("限时活动领取奖励", LOG_DEBUG)
        return true
    end
    return false
end


-- 限时活动领取奖励关闭
function fz_xsjl_lingQu_GB()
    x, y = findMultiColorInRegionFuzzy(0xa46626, "15|-21|0xf4ce6c,12|14|0x93541e,-21|19|0x83471a,-20|-12|0xc98a34,10|-16|0xe5b457,7|10|0x8f521e,-25|-11|0xdc9a32", 78, 805, 100, 1008, 299, 0, 0)
    if x > -1 then
        click(x, y)
        logger("限时活动领取奖励关闭", LOG_DEBUG)
        return true
    end
    return false
end


-- 任务
function fz_renWu_ui()

    x, y = findMultiColorInRegionFuzzy(0xfef8c7, "-141|14|0x3b0b00,67|12|0x3b0b00,171|3|0x682220,-247|10|0x692320,-72|1|0xfef7c4,-55|6|0xfef0b2,-47|21|0xfedc7b,-3|0|0xfef8c7,14|8|0xf6e5a5,-1|12|0xfee89b,0|20|0x2c0800,-16|22|0x2c0800", 78, 0, 0, 1079, 1919, 0, 0)
    if x > -1 then
        click(x, y)
        logger("任务界面", LOG_DEBUG)
        return true
    end
end
-- 任务领取
function fz_renWu_lingQu()

    local x, y = findMultiColorInRegionFuzzy(0xb95e23, "55|-12|0xca7431,137|1|0xb96126,122|32|0x572910,85|43|0x4e2816,17|24|0x7c401c,86|20|0x7a3d1b,92|9|0xb45a1f,65|8|0xbd5e20", 78, 743, 556, 1037, 1914, 0, 0)
    if x > -1 then
        click(x, y)
        logger("任务领取", LOG_DEBUG)
        return true
    end

end

-- 任务关闭
function fz_renWu_ui_gb()

    local x, y = findMultiColorInRegionFuzzy(0xfeda3c, "19|-15|0xfef363,9|10|0xfec820,-15|15|0xfec115,-10|-6|0xfee54e", 78, 915, 63, 1058, 234, 0, 0)
    if x > -1 then
        click(x, y)
        logger("任务界面关闭", LOG_DEBUG)
        return true

    end
end
-- 任务
function fz_renWu_ui()

    x, y = findMultiColorInRegionFuzzy(0xfbf3d2, "-9|-19|0xc97231,73|-2|0xb1581f,18|31|0x532a13,-33|14|0x85451d,-17|14|0x783d19,12|6|0xae551d", 78, 732, 533, 1042, 1913, 0, 0)
    if x > -1 then
        click(x, y)
        logger("任务界面", LOG_DEBUG)
        return true
    end
end

-- 任务-活跃度
function fz_renWu_huoRueDu()
    x, y = findMultiColorInRegionFuzzy(0xcfc23a, "51|-20|0xb9ab33,81|17|0x7d7229,80|41|0x837a48,17|68|0x786e41", 78, 241, 221, 1055, 386, 0, 0)
    if x > -1 then
        click(x, y)
        logger("任务活跃度奖励", LOG_DEBUG)
        return true
    end

end

-- 成就
function fz_chengJiu_ui()
    x, y = findMultiColorInRegionFuzzy(0xe52918, "9|-6|0xfb6f40,6|5|0xde160b,-6|5|0xe42110,-8|-4|0xf8663e,810|-177|0xfee54e", 78, 0, 0, 1079, 1919, 0, 0)
    if x > -1 then
        click(x, y)
        logger("成就界面", LOG_DEBUG)
        return true
    end
end
-- 成就
function fz_chengJiu_ui_gb()
    local x, y = findMultiColorInRegionFuzzy(0xfed12f, "11|-16|0xfeec58,9|10|0xfec115,-18|11|0xfebf12,-15|-13|0xfee750,-27|-7|0xc23310,-8|16|0xdb4b13,20|-6|0xc6380f,5|-22|0xa7200c", 78, 925, 78, 1079, 241, 0, 0)
    if x > -1 then
        click(x, y)
        logger("成就界面关闭", LOG_DEBUG)
        return true
    end
end


-- 成就- 可以领取的
function fz_chengJiufind()
    local x, y = findMultiColorInRegionFuzzy(0xe01509, "7|-9|0xea341e,-7|-8|0xeb381f,-3|-12|0xf14729,4|-5|0xde170d,3|-6|0xe01c10", 78, 173, 255, 234, 1855, 0, 0)
    if x == -1 then
        x, y = findMultiColorInRegionFuzzy(0xe01509, "7|-9|0xea341e,-7|-8|0xeb381f,-3|-12|0xf14729,4|-5|0xde170d,3|-6|0xe01c10", 78, 687, 269, 754, 1832, 0, 0)
    end
    if x > -1 then
        click(x, y)
        logger("成就- 可以领取的", LOG_DEBUG)
        return true
    end
end
-- 成就-领取
function fz_chengJiu_lingQu()

    x, y = findMultiColorInRegionFuzzy(0xcab89d, "-28|-25|0xc96f2f,28|-5|0xb25a20,24|26|0x502816,-59|17|0x5e3018,-78|-10|0xae5922,-53|-23|0xc86d2e,-27|-4|0x7f604c,-25|12|0xfbf2d2,10|6|0xfff7d6", 78, 0, 0, 1079, 1919, 0, 0)
    if x > -1 then

        click(x, y)
        logger("成就-领取", LOG_DEBUG)
        return true
    end

end

-- 成就-领取
function fz_chengJiu_lingQu_gb()

    local x, y = findMultiColorInRegionFuzzy(0xfee34b, "20|-18|0xfee34b,12|15|0xfee34b,-19|17|0xfee34b,-16|-13|0xfee34b,-30|-5|0x1e2b43,2|-27|0x1e2b43,27|0|0x1e2b43,-7|28|0x1e2b43", 78, 0, 0, 1079, 1919, 0, 0)
    if x > -1 then
        click(x, y)
        logger("成就-领取关闭", LOG_DEBUG)
        return true
    end

end

-- 成就-主线任务
function fz_zhuXian_ui()
    x, y = findMultiColorInRegionFuzzy(0x543624, "-79|-13|0xdfdcb9,-91|-2|0xfef7c5,-61|-3|0xfef9c7,-75|6|0xfeeeac,-75|18|0xfedf84,-4|-5|0xfefacd,1|4|0xfef1b3,25|8|0x3b0b00,60|8|0xfeeca6", 78, 278, 531, 847, 712, 0, 0)
    if x > -1 then

    end
end


-- 成就-主线任务-关闭
function fz_zhuXian_ui()
    x, y = findMultiColorInRegionFuzzy(0xfee34b, "-15|-20|0xfee452,17|-21|0xfef099,8|13|0xfee34b,-23|17|0xfee453,-35|-2|0x1e2b43,-7|-30|0x1e2b43,19|-7|0x293343,-8|23|0x1e2b43", 78, 0, 0, 1079, 1919, 0, 0)
    if x > -1 then

    end
end
-- 成就-主线任务-关闭
function fz_zhuXian_ui_gb()
    local x, y = findMultiColorInRegionFuzzy(0xfee34b, "6|-28|0x1e2b43,45|-1|0x1e2b43,5|36|0x1e2b43,-15|4|0x1e2b43,9|14|0xfee34b,-8|14|0xfee34b,-10|-5|0xe7ce44", 78, 878, 573, 1079, 726, 0, 0)
    if x > -1 then
        click(x, y)
        return false
    end
end
-- 成就-主线任务-领取
function fz_zhuXian_lingQu()
    local x, y = findMultiColorInRegionFuzzy(0xe4d7b8, "-13|-17|0xc4692c,76|-15|0xc2672a,57|8|0x9a4c1c,38|25|0x633319,5|27|0x5e3119,12|0|0x5c2e17,5|0|0xdaccae,17|-632|0x3b0b00,52|-632|0xfeeca6", 78, 212, 1195, 863, 1333, 0, 0)
    if x > -1 then
        click(x, y)
        logger("主线任务-领取", LOG_DEBUG)
        return true
    end
end

function fz_allClose()
    -- 显示奖励
    fz_xsjl_ui_gb()
    fz_xsjl_lingQu_GB()
    -- 成就
    fz_chengJiu_ui_gb()
    fz_chengJiu_lingQu_gb()
    --任务
    fz_renWu_ui_gb()
    -- 红颜
    fz_HongYong_GB()
    -- 任务
    fz_renWu_ui_gb()
    -- 儿子
    fz_erZi_ui_GB()
    -- 资产& 政务
    fz_ZiChan_UI_GB()
    -- 网络连接失败
    wangLuoLianJieShiBai()
    click_kong()
end

function fz_fanHuiUi()

    flag = fz_ui()
    if flag then
        return
    end
    flag = false;
    local index = 1
		
    while not (flag) do
        logger(string.format("第%s次尝试返回府宅", index), LOG_DEBUG)
				wangLuoLianJieShiBai()
        jingRuYouXi()
		    gongGaoGuanBi()
        fz_allClose()
        flag = fz_ui()
        index = index + 1
    end

end


---------------------------------------------
---------------------------------------------
------------    功能  ---------------------
---------------------------------------------

-- 运行成就
function fz_xsjl_run()
    logger("进入限时奖励", LOG_DEBUG)
    -- 当前页面是否能已领取

    for tmpi = 1, 3 do

        local pageChengJiu = true;
        while pageChengJiu do
            pageChengJiu = false;
            -- 领取
            logger("检测是否有奖励可以领取", LOG_DEBUG)
            local flag = fz_xsjl_findHuoDong()

            -- 检测领取页面
            local pageFlag2 = true;
            while flag do
                mSleep(1000)
                pageFlag2 = false;
                -- 检测领取按钮
                flag = true;
                while flag do
                    flag = fz_xsjl_lingQu()
                    -- 当前页领取过
                    if flag then
                        pageFlag2 = true;
                    end
                    mSleep(2000)
                end
                -- 如果当前页领取过，则检测下一页
                if pageFlag2 then
                    pageChengJiu = true;
                    szMove(551, 1400, 549, 400)
                end
                mSleep(1000)

            end
            fz_xsjl_lingQu_GB()
            mSleep(1000)
        end




        -- 如果当前页领取过，则检测下一页

        szMove(555, 1300, 539, 279)

        mSleep(1000)
    end



    fz_xsjl_ui_gb()
    logger("退出 《限时奖励》", LOG_DEBUG)
end

--  run
-- 限时奖励运行
--function fz_xsjl_run()
--  local flag=false
--  logger("进入限时奖励",LOG_DEBUG)
--  -- 处理3次
--  for tmpi=1,3 do

--    hongflag=true;
--    while hongflag do
--		  logger("查找限时活动",LOG_DEBUG)
--      flag=fz_xsjl_findHuoDong();
--      hongflag=flag
--      while flag do
--        local pageFlag=false;
--        logger("查找奖品领取按钮",LOG_DEBUG)

--        -- 查找是否可以领取
--        flag= true
--        while flag do
--          mSleep(1000)
--          flag=fz_xsjl_lingQu()

--          if flag then 
--            pageFlag=true;
--          end 
--        end
--        -- 领取过则翻页
--        if pageFlag then
--          szMove(551,1400,549,400)
--          mSleep(1000)
--        end 
--      end
--    end

--    fz_xsjl_lingQu_GB()
--    szMove(551,1581,549,281)
--    mSleep(1000)
--  end
--  fz_xsjl_ui_gb()
--end 

-- 任务
function fz_renWu_run()

    logger("进入 《任务》", LOG_DEBUG)
    -- 当前页面是否能已领取
    local pageFlag = true;
    while pageFlag do
        pageFlag = false;
        -- 领取
        local flag = true
        while flag do

            mSleep(2000)
            flag = fz_renWu_lingQu()

            if flag then
                pageFlag = flag;
            end

        end

        if pageFlag then
            mSleep(1000)
            szMove(578, 1870, 559, 580)
        end

        mSleep(1000)
    end

    flag = true
    while flag do
        flag = fz_renWu_huoRueDu()
        mSleep(1000)
    end


    fz_renWu_ui_gb()
    logger("退出 《任务》", LOG_DEBUG)
end

-- 运行成就
function fz_chengjiu_run()
    logger("进入 《成就》", LOG_DEBUG)
    -- 当前页面是否能已领取

    for tmpi = 1, 3 do

        local pageChengJiu = true;
        while pageChengJiu do
            pageChengJiu = false;
            -- 领取
            logger("检测是否有成就可以领取", LOG_DEBUG)
            local flag = fz_chengJiufind()

            -- 检测领取页面
            local pageFlag2 = true;
            while flag do
                pageFlag2 = false;
                mSleep(1000)
                -- 检测领取按钮
                flag = true;
                while flag do
                    flag = fz_chengJiu_lingQu()
                    -- 当前页领取过
                    if flag then
                        pageFlag2 = true;
                    end
                    mSleep(2000)
                end
                -- 如果当前页领取过，则检测下一页
                if pageFlag2 then
                    pageChengJiu = true;
                    szMove(576, 1100, 557, 470)
                end
                mSleep(1000)

            end
            fz_chengJiu_lingQu_gb()
            mSleep(1000)
        end




        -- 如果当前页领取过，则检测下一页
        szMove(555, 1300, 539, 279)

        mSleep(1000)
    end



    fz_chengJiu_ui_gb()
    logger("退出 《成就》", LOG_DEBUG)
end

-- 府宅 经营资产
function fz_ZiChan_run(noClose)
    local flag = fz_ZiChan_UI()
    if not (flag) then
        return
    end
    logger(" 《经营资产》", LOG_DEBUG)
    mSleep(1000)

    while flag do
        flag = false
        -- 经营 按钮
        x, y = findMultiColorInRegionFuzzy(0xc46c2e, "84|1|0xc96f2f,170|1|0xc26a2d,196|40|0x82431c,-11|60|0x7f4615,209|57|0x864b1b,228|131|0x252034,-345|136|0x252034,-697|-20|0x211c2e", 80, 604, 412, 1035, 1815, 0, 0)
        --logger(tostring(x).."  "..tostring(y),LOG_DEBUG)
        if x > -1 then
            click(x, y)
            flag = true
        end

        --断网界面
        x, y = findMultiColorInRegionFuzzy(0xbd652a, "188|-5|0xc36c2e,207|51|0x8c5525,-17|54|0x7e4516,-320|-206|0xfecf92,470|-206|0xfecf92,566|-122|0xfecf92,569|71|0xfecf92,465|133|0x452a17,-185|139|0xfecf92,-379|76|0xfecf92,-380|-124|0xfecf92", 80, 0, 0, 1079, 1919, 0, 0)
        if x > -1 then
            click(x, y)
        end
        mSleep(2000)
    end

    if not (noClose) then
        fz_ZiChan_UI_GB()
    end
    return true
end

--- 政务
function fz_zhenWu_run()
    local flag = fz_zhenWu_UI()
    if not (flag) then
        return
    end
    logger(" 《政务》", LOG_DEBUG)
    mSleep(1000)


    --检测有无政务
    while flag do
        flag = fz_zhenWu_zw();

        if flag then

            --领资源
            if fz_zhengWu_ZiYuan then
                fz_zhenWu_ziYuan()
            end

            if fz_zhengWu_ZhenWu then
                fz_zhenWu_zhenJi()
            end

        end
        mSleep(5000)
        wangLuoLianJieShiBai()
    end

    fz_ZiChan_UI_GB()
    mSleep(1000)
    return true
end


-- 儿子
function fz_erZi_run()
    local flag = fz_erZi_ui()
    if not (flag) then
        return
    end
    logger(" 《子嗣》", LOG_DEBUG)






    -- todo 处理多个子嗣
    --处理子嗣功能
    while flag do
        --

        fz_erZi_peiYang()
        fz_erZi_ciMing()
        fz_erZi_ciMing_queDing()
        fz_erZi_keJu()

        click(1062, 901)
        mSleep(200)
        flag = fz_erZi_huiFu_No();
        flag = not (flag)
        wangLuoLianJieShiBai()
    end

    fz_erZi_ui_GB()
    mSleep(1000)
    return true
end


-- 红颜
function fz_hongYan_run()
    local flag = fz_hongYan_ui()
    if not (flag) then
        return
    end

    --随机传唤
    while flag do
        fz_hongYan_suiJiChuanHuan()
        mSleep(300)
        click(954, 1733)
        mSleep(300)

        fz_hongYan_haizi()
        mSleep(300)
        flag = fz_hongYan_huiFuJinLi()
        flag = not (flag )
        wangLuoLianJieShiBai()
    end

    fz_HongYong_GB()
    mSleep(1000)

    -- todo  儿子解锁
    local erzzflag=fz_erZi_jieSuo()
    if erzzflag then
        -- 判断是否进入儿子界面
        if fz_erZi_ui() then
            fz_erZi_ui_GB()
            mSleep(1000)
        end
    end

    return true
end



function fz_checkShouZhi()
    flag = false
    for i, func in ipairs({ fz_shouZhi, fz_HuangKuang, fz_meiPo_jiesuo }) do
        flag = func()
        if flag then
            break;
        end
    end

    if not (flag) then
        return
    end

    while flag do
        local flag1 = false;
        for i, func in ipairs({ fz_ui, fz_HongYong_GB, fz_erZi_ui_GB }) do
            flag1 = func()
            if flag1 then
                return
            end
        end

        click(13, 1449)
        fz_erZi_ciMing()
        fz_erZi_ciMing_queDing()
        wangLuoLianJieShiBai()
    end
end


---- 府宅运行
function fz_run( isClose)
    local flag = false

    szMove(91, 691, 980, 691)
    mSleep(100)
    szMove(91, 691, 980, 691)

    mSleep(500)
    -- 限时奖励

    if fz_fuJia_xianShi then
        logger("开始检测 《限时奖励》", LOG_DEBUG)

        flag = fz_jc_xianshijianli()
        if flag then
            logger("进入《限时奖励》", LOG_DEBUG)
            fz_xsjl_run()
        end

    end


    -- 任务

    if fz_fuJia_renWu then
        logger("开始检测 《任务》", LOG_DEBUG)
        flag = fz_jc_renWu()
        if flag then
            logger("进入《任务》", LOG_DEBUG)
            fz_renWu_run()
        end
    end

    --成就
    if fz_fuJia_chengJiu then
        logger("开始检测 《成就》", LOG_DEBUG)
        flag = fz_jc_chengJiu()
        if flag then
            logger("进入《成就》", LOG_DEBUG)
            fz_chengjiu_run()
        end
    end

    for tmpi = 1, 2 do
        logger("检测需要操作事件", LOG_DEBUG)
        mSleep(1000)
        --资产经营
        if fz_gongNeng_ziChan then
            flag = fz_huaAn2()
            if flag then
                fz_ZiChan_run()
            end
        end

        --政绩
        if fz_gongNeng_zhengWu then
            flag = fz_shiYe()
            if flag then
                fz_zhenWu_run()
            end
        end

        flag=true
        while flag and fz_gongNeng_zhiSi do
            --儿子
            flag = fz_zhiSi()
            if flag then
                fz_erZi_run()
            else
                break
            end
        end



        --红颜
        if fz_gongNeng_HongYan then
            flag = fz_hongYan()
            if flag then
                fz_hongYan_run()
            end
        end

        -- 检测手指
        mSleep(1000)
        fz_checkShouZhi()
        wangLuoLianJieShiBai()
        logger("移动地图", LOG_DEBUG)
        szMove(840, 691, 200, 691)
        mSleep(3000)

    end
    logger("完成府宅", LOG_DEBUG)
    mSleep(2000)

    if isClose then
        fz_ui_gb()
    end

end








function fz_only_ziChan()

    -- 检测是否是资产界面
    x, y = findMultiColorInRegionFuzzy(0x3b0b00, "-242|2|0x692320,489|1|0x73291c,-362|-84|0xbf783e,-331|-115|0x471d05,465|194|0x252034,-372|351|0x201c2e,247|349|0x494038", 80, 6, 6, 1078, 581, 0, 0)
    if x > -1 then
        flag = true;
    end

    -- 不是则点击华安
    while not (flag) do
        szMove(91, 691, 980, 691)
        mSleep(1000)
        flag = fz_huaAn()
        if flag then
            break
        end
    end

    logger(" 《经营资产》", LOG_DEBUG)
    while true do
        mSleep(1000)

        -- 经营 按钮
        x, y = findMultiColorInRegionFuzzy(0xc46c2e, "84|1|0xc96f2f,170|1|0xc26a2d,196|40|0x82431c,-11|60|0x7f4615,209|57|0x864b1b,228|131|0x252034,-345|136|0x252034,-697|-20|0x211c2e", 80, 604, 412, 1035, 1815, 0, 0)
        --logger(tostring(x).."  "..tostring(y),LOG_DEBUG)
        if x > -1 then
            click(x, y)
        end

        --断网界面
        x, y = findMultiColorInRegionFuzzy(0xbd652a, "188|-5|0xc36c2e,207|51|0x8c5525,-17|54|0x7e4516,-320|-206|0xfecf92,470|-206|0xfecf92,566|-122|0xfecf92,569|71|0xfecf92,465|133|0x452a17,-185|139|0xfecf92,-379|76|0xfecf92,-380|-124|0xfecf92", 80, 0, 0, 1079, 1919, 0, 0)
        if x > -1 then
            click(x, y)
        end
        wangLuoLianJieShiBai()
    end


end